package com.lineage.data.item_etcitem.shop;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1PolyMorph;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class PolyUserSet extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(PolyUserSet.class);
  
  private int _polyid = -1;
  
  private int _time = 1800;
  
  public static ItemExecutor get() {
    return new PolyUserSet();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int awakeSkillId = pc.getAwakeSkillId();
    if (awakeSkillId == 185 || awakeSkillId == 190 || awakeSkillId == 195) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(1384));
      return;
    } 
    if (this._polyid == -1) {
      int itemId = item.getItemId();
      _log.error("自定义变身卷轴 设定错误: " + itemId + " 没有变身代号!");
      return;
    } 
    pc.getInventory().removeItem(item, 1L);
    L1PolyMorph.doPoly((L1Character)pc, this._polyid, this._time, 1);
  }
  
  public void set_set(String[] set) {
    try {
      this._polyid = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
    try {
      this._time = Integer.parseInt(set[2]);
    } catch (Exception exception) {}
  }
}
